﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

namespace SchedulerControl
{
    public partial class ScheduleItemWindow : ChildWindow
    {
        private AppointmentItemMetaData _metaData;
        public AppointmentItemMetaData MetaData
        {
            get
            {
                return _metaData;
            }
            set
            {
                _metaData = value;
                RefreshFields();
            }
        }


        public ScheduleItemWindow()
        {
            InitializeComponent();
        }

       

        private void OKButton_Click(object sender, RoutedEventArgs e)
        {
            if (this.tpStartTime.Value >= this.tpEndTime.Value) return;

            if (this.tpStartTime.Value != null)
            {
                MetaData.StartTime = (DateTime)this.tpStartTime.Value;
            }

            if (this.tpEndTime.Value != null)
            {
                MetaData.EndTime = (DateTime)this.tpEndTime.Value;
            }
            
            MetaData.ItemDate = (DateTime)this.dpDate.SelectedDate;
            MetaData.Subject = this.tbSubject.Text;
            MetaData.Description = this.tbDescription.Text;   

            this.DialogResult = true;
        }

        private void CancelButton_Click(object sender, RoutedEventArgs e)
        {
            this.DialogResult = false;
        }

        private void RefreshFields()
        {
            this.tpStartTime.Value = MetaData.StartTime;
            this.tpEndTime.Value = MetaData.EndTime;
            this.dpDate.SelectedDate = MetaData.ItemDate;
            if (MetaData.Subject != null) this.tbSubject.Text = MetaData.Subject;
            if(MetaData.Description != null) this.tbDescription.Text = MetaData.Description ;   
        }
    }
}

